% 计算频谱
function [f, P1] = computeSpectrum(signal, sampleRate)
    L = length(signal);
    Y = fft(signal);
    P2 = abs(Y / L);
    P1 = P2(1:floor(L / 2) + 1);
    P1(2:end-1) = 2 * P1(2:end-1);
    f = sampleRate * (0:floor(L / 2)) / L;
end